package net.jdm.common;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Alert {
	public enum AlertLevel {
		INFO{
			@Override
			public void print(String message){
			 if (LOG.isInfoEnabled() || LOG.isDebugEnabled()) {
				LOG.info(message);
			  }
			}
		}, WARN{
			@Override
			public void print(String message){
				if (LOG.isWarnEnabled() || LOG.isDebugEnabled()) {
					LOG.warn(message);
				}
			}
		}, ERROR{
			@Override
			public void print(String message){
				if (LOG.isErrorEnabled() || LOG.isDebugEnabled()) {
					LOG.error(message);
				}
			}
		}, FATAL{
			@Override
			public void print(String message){
				if (LOG.isFatalEnabled() || LOG.isDebugEnabled()) {
					LOG.fatal(message);
				}
			}
		};
		private static final Log LOG = LogFactory.getLog(AlertLevel.class);
		abstract public void print(String message);
	}
	public static final Map<String, AlertLevel> ALERT_LEVEL_MAP = new HashMap<String, AlertLevel>();

	static {
		ALERT_LEVEL_MAP.put(AlertLevel.INFO.name(), AlertLevel.INFO);
		ALERT_LEVEL_MAP.put(AlertLevel.WARN.name(), AlertLevel.WARN);
		ALERT_LEVEL_MAP.put(AlertLevel.ERROR.name(), AlertLevel.ERROR);
		ALERT_LEVEL_MAP.put(AlertLevel.FATAL.name(), AlertLevel.FATAL);
	}

	public enum DetailLevel {
		LOW,MIDDLE,HIGH
	}
	public static final Map<String, DetailLevel> DETAIL_LEVEL_MAP = new HashMap<String, DetailLevel>();

	static {
		DETAIL_LEVEL_MAP.put(DetailLevel.LOW.name(), DetailLevel.LOW);
		DETAIL_LEVEL_MAP.put(DetailLevel.MIDDLE.name(), DetailLevel.MIDDLE);
		DETAIL_LEVEL_MAP.put(DetailLevel.HIGH.name(), DetailLevel.HIGH);
	}

	protected String alertMessage;
	private AlertLevel alertLevel=AlertLevel.WARN;
	private DetailLevel detailLevel=DetailLevel.MIDDLE;
	public String getAlertMessage() {
		return (alertMessage==null)?"":alertMessage;
	}

	public void setAlertMessage(String alertMessage) {
		this.alertMessage = alertMessage;
	}

	public void setAlertLevel(AlertLevel alertLevel) {
		this.alertLevel = alertLevel;
	}

	public AlertLevel getAlertLevel() {
		return alertLevel==null?AlertLevel.WARN:alertLevel;
	}
	public void setDetailLevel(DetailLevel detailLevel) {
		this.detailLevel = detailLevel;
	}
	public DetailLevel getDetailLevel() {
		return detailLevel==null?DetailLevel.LOW:detailLevel;
	}
}
